package cn.leedsoft.and.crimeintent.controller.hellomoon;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import cn.leedsoft.and.crimeintent.R;
import cn.leedsoft.and.crimeintent.model.AudioPlayer;

/**
 * Created by leeds on 2016/8/9 16:10.
 */
public class AudioFragment extends Fragment{
    private AudioPlayer mAudioPlayer = new AudioPlayer();
    private Button mPlayButton;
    private Button mStopButton;

    public static AudioFragment newInstance() {

        Bundle args = new Bundle();

        AudioFragment fragment = new AudioFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.hellomoon_fragment_audio, container, false);
        mPlayButton = (Button) view.findViewById(R.id.hellomoon_playbutton);
        mStopButton = (Button) view.findViewById(R.id.hellomoon_stopbutton);

        mPlayButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mAudioPlayer.play(getActivity());
            }
        });
        mStopButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mAudioPlayer.stop();
            }
        });

        return view;
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mAudioPlayer.stop();
    }
}
